<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="../../common/taglibs.jsp" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	     <title>${orderId}订单产品管理</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<link rel="stylesheet" type="text/css" href="<%=basePath%>CSS/layout.css" />
          <style type="text/css">  
    .tdFirstColor {  
         background-color: #C00;  
     }  
     .tdSecondColor {  
         background-color: yellow;  
      }  
     .tdOverColor {  
        background-color: #F90;  
      }  
      .thColor{  
        background-color:aqua;  
      }  
      <!--
       tr {background-color:expression((this.sectionRowIndex%2==0)?"#E1F1F1":"#F0F0F0")}
      -->
</style> 
  </head>
  <body>
  <div id="wrapper">
    <!--头部菜单开始-->
    <jsp:include page="/common/head.jsp"></jsp:include>
    <!--头部菜单结束-->
	<div id="BreadCrumb">我的位置：基本资料管理 &gt; 订单产品管理</div>
	<div id="REC_content">
	    <fieldset id="BasicInfo" class="mainField">
		    <legend><span class="title">订单产品管理</span></legend>
			<div class="innerCon">
			    <div class="info">
				</div>
				<div id="mainListCon">
				    <div class="tableCon">
					    <ul>
						    <li id="result">
							    <table width="100%" style="border:1px solid #eee;font-family: fantasy;" cellpadding="0" cellspacing="1" >
								    <tr bgcolor="#f2f6f9">
                                      <th width="10%"><a href="javascript:openAll()" id="allItems">展开</a></th>
                                      <th width="5%"><fmt:message key="pdtOrder.trackNo"/></th>
                                      <th width="20%"><fmt:message key="pdtOrder.cmtPdtOrderId"/></th>
                                      <th width="20%"><fmt:message key="pdtOrder.cmtPdtId"/></th>
                                      <th width="20%"><fmt:message key="pdtOrder.arriveDate"/></th>
                                      <th width="15%"><fmt:message key="pdtOrder.sendDate"/></th>
                                      <th width="10%"><fmt:message key="pdtOrder.orderNum"/></th>
									</tr>
									
									<c:forEach var="order" items="${dataList.pageList}" varStatus="idex">
                                      <tr id="order${order.cmtpdtorderid}" class="${idex.index%2==0?'list1':'list2'}" align="center">
                                          <td><a id="show${order.cmtpdtorderid}" href="javascript:getOrderItem('${order.cmtpdtorderid}')">展开</a></td>
                                          <td>${order.trackNo}</td>
                                          <td><a href="#" onclick="javascript:showItems('${order.cmtpdtorderid}')">${order.cmtpdtorderid}</a></td>
                                          <td>${order.cmtpdtid}</td>
                                          <td><fmt:formatDate value="${order.arrivedate}"/></td>
                                          <td><fmt:formatDate value="${order.senddate}"/></td>
                                          <td>${order.ordernum}</td>
                                       </tr>
                                    </c:forEach>
								</table> 
							</li>
						</ul>
					</div>
				</div>
			</div>
		</fieldset>
	</div>
	<jsp:include page="/common/foot.jsp"></jsp:include>
	<script type="text/javascript" src="js/jquery.js"language="javascript"></script>
          <script src='<%=basePath%>dwr/interface/productImportServices.js'></script>
          <script src="<%=basePath%>dwr/engine.js"></script>
          <script type="text/javascript" src="js/ftyUtils.js"language="javascript"></script>
           <script type="text/javascript" language="javascript">
           function showItems(cmtPdtOrderId){
              window.open("<%=basePath%>getProduct.do?sku="+cmtPdtOrderId+"&orderId=${orderId}", "_blank");
           }
           
           function cancel(sku,cmtSku){
              productImportServices.cancelProduct(sku,function(){
                 alert("取消【"+sku+"】成功!");
                 hiddenItems(cmtSku);
              });
           }
        $(document).ready(function(){
            $("a[id^=show]").toggle(
                function(data){
                    var sku = this.id.substring(4);
                    getOrderItem(sku);
                },function(){
                    var sku = this.id.substring(4);
                    hiddenItems(sku);
             });
             
             $("#allItems").toggle(
                function(){
                    openAll();
                },function(){
                   closeAll();
             });
             
             $("#dataTable tr").mouseover(function(){$(this).addClass("tdOverColor");}).mouseout(function(){$(this).removeClass("tdOverColor");}); 
             $("#dataTable tr:even").addClass("tdSecondColor");
         });
         
         function openAll(){
             $("tr[id^=order]").each(function(data){
                $("#allItems").text("全部收起");
                getOrderItem(this.id.substring(5));
             });
         }
         
         function closeAll(){
             $("tr[id^=order]").each(function(data){
                $("#allItems").text("全部展开");
                hiddenItems(this.id.substring(5));
             });
         }
         
         function hiddenItems(sku){
            $("#orderItem"+sku).hide();
            $("#show"+sku).text("展开");
         };
         
         function getOrderItem(sku){
           $("#show"+sku).text("收起");
           $("#show"+sku).attr("href","#");
           $("#orderItem"+sku).remove();
           var orderId = "${orderId}";
           productImportServices.getProductByOrderIdSku(orderId,sku,function (data){
           var orderItemsTr = "<td colspan=7 id='orderItem"+sku+"'><div><table width='100%' border=1 style='font-family: Verdana;font-size: 12px;'><tr>";
           orderItemsTr+='<th><fmt:message key="product.pdtskuid"/></th>';
           orderItemsTr+='<th><fmt:message key="product.cmtOrderId"/></th>';
           orderItemsTr+='<th><fmt:message key="product.cmtpdtid"/></th>';
           orderItemsTr+='<th><fmt:message key="product.cmtpdtskuid"/></th>';
           orderItemsTr+='<th><fmt:message key="product.importdate"/></th>';
           orderItemsTr+='<th><fmt:message key="product.styleno"/></th>';
           orderItemsTr+='<th><fmt:message key="product.routeType"/></th>';
           orderItemsTr+='<th><fmt:message key="product.sendDate"/></th>';
           orderItemsTr+='<th><fmt:message key="product.pdtStatus"/></th>';
           orderItemsTr+='<th></th>';
           orderItemsTr+="</tr>";
               for(var product in data){
                 orderItemsTr+="<tr>";
                 orderItemsTr+="<td><a target='_blank' href='wip.do?proId="+data[product].pdtskuid+"'>"+data[product].pdtskuid+"</a></td>";
                 orderItemsTr+="<td>"+data[product].cmtOrderId+"</td>";
                 orderItemsTr+="<td>"+data[product].cmtpdtid+"</td>";
                 orderItemsTr+="<td>"+data[product].cmtpdtskuid+"</td>";
                 
                  var importdate = new Date(data[product].importdate);
                 orderItemsTr+="<td>"+importdate.format("YYYY-MM-dd")+"</td>";
               
                 //orderItemsTr+="<td>"+importdate+"</td>";
                 orderItemsTr+="<td>"+data[product].styleno+"</td>";
                 
                 if(isEmpty(data[product].routeId)){
                   orderItemsTr+="<td><a target='_blank' href='wip.do?proId="+data[product].pdtskuid+"'>设置路由</a></td>";
                 }else
                   orderItemsTr+="<td><a target='_blank' href='wip.do?proId="+data[product].pdtskuid+"'>"+data[product].routeId+"</a></td>";
                   
                 if(isEmpty(data[product].sendDate)){
                   orderItemsTr+="<td><fmt:message key='product.pdtStatus6'/></td>";
                 }else{
                   var sendDate = new Date(data[product].sendDate);
                   orderItemsTr+="<td>"+sendDate.format("YYYY-MM-dd")+"</td>";
                 }
                 
                 switch(data[product].pdtStatus){
                  case 1:
                    orderItemsTr+="<td><fmt:message key='product.pdtStatus1'/></td>";
                    orderItemsTr+="<td><input type='button' value='取消' onclick='cancel(\""+data[product].pdtskuid+"\",\""+data[product].cmtpdtskuid+"\")'/></td>";
                    break;
                  case 2:
                    orderItemsTr+="<td><fmt:message key='product.pdtStatus2'/></td>";
                    orderItemsTr+="<td><input type='button' value='取消' onclick='cancel(\""+data[product].pdtskuid+"\",\""+data[product].cmtpdtskuid+"\")'/></td>";
                    break;
                  case 3:
                    orderItemsTr+="<td><fmt:message key='product.pdtStatus3'/></td>";
                    orderItemsTr+="<td><input type='button' value='取消' onclick='cancel(\""+data[product].pdtskuid+"\",\""+data[product].cmtpdtskuid+"\")'/></td>";
                    break;
                  case 4:
                    orderItemsTr+="<td><fmt:message key='product.pdtStatus4'/></td>";
                    orderItemsTr+="<td></td>";
                    break;
                  case 5:
                    orderItemsTr+="<td><fmt:message key='product.pdtStatus5'/></td>";
                    orderItemsTr+="<td></td>";
                    break;
                  case 6:
                    orderItemsTr+="<td><fmt:message key='product.pdtStatus6'/></td>";
                    orderItemsTr+="<td></td>";
                    break;
                  case 7:
                    orderItemsTr+="<td><fmt:message key='product.pdtStatus7'/></td>";
                    orderItemsTr+="<td></td>";
                    break;
                  default:
                    orderItemsTr+="<td><fmt:message key='product.pdtStatus1'/></td>";
                    orderItemsTr+="<td><input type='button' value='取消' onclick='cancel(\""+data[product].pdtskuid+"\",\""+data[product].cmtpdtskuid+"\")'/></td>";
                    break;
                 }
                 orderItemsTr+="</tr>";
              }
              orderItemsTr+="</table></div></td>";
              $("#order"+sku).after(orderItemsTr);
              //$(orderItemsTr).insertAfter("#order"+sku);
            });   
            
         }
           </script>
</div>
   </body>
</html>
